<?php

/*

  Action	$4

  Trash this and another copy of Treasure Map from your hand.
  If you do trash two Treasure Maps, gain 4 Gold cards, putting them on top of your deck.

 */

class TreasureMap extends Card implements iAction, iKingdom, iSeaside {

    public function __construct() {
        parent::__construct("Treasure Map", 4);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "Trash this and another copy of Treasure Map from your hand.  If you do trash two Treasure Maps, gain 4 Gold cards, putting them on top of your deck.");
    }
    
    public function play(Game $game, $isRealCard) {

        $first_tm = $game->moveCardFromPileToPile($this, PlayArea, Trash);
         ScreenDisplay::addScreenMessage($game, true, "trash ".  nicePrint($this), "trashes ".  nicePrint($this));

        //now we check if player has another tm in hand
        $second_tm = $game->moveCardFromPileToPile($this, PlayHand, Trash);
        if ($second_tm) {
            //he does
            $g1 = $game->moveCardFromPileToPile("Gold", BoardCards, DrawPile);
            $g2 = $game->moveCardFromPileToPile("Gold", BoardCards, DrawPile);
            $g3 = $game->moveCardFromPileToPile("Gold", BoardCards, DrawPile);
            $g4 = $game->moveCardFromPileToPile("Gold", BoardCards, DrawPile);

            $golds = array();
            if ($g1) 
                $golds[] = $g1;
            if ($g2) 
                $golds[] = $g2;
            if ($g3) 
                $golds[] = $g3;
            if ($g4) 
                $golds[] = $g4;
            
             ScreenDisplay::addScreenMessage($game, false, " and another ".  nicePrint($this)." and gain".  nicePrint($golds), " and another ".  nicePrint($this)." and gains".  nicePrint($golds));
            
        }
		$game->cardActionFinished();
        return true;
    }

}

?>